/**
  ETFDAQ Project
  \brief Registers and ROM of a general mesytec card
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2024-09-05
  \date 2024-09-05 last modified

  \copyright Copyright (c) 2024 IMP-CAS with LGPLv3 LICENSE
*/

#ifndef mesy_reg_h
#define mesy_reg_h

// control and data registers -- generally true, yet quite a few exceptions do exist
struct mesyreg{
  // data fifo
  static constexpr uint16_t dataFIFO =           0x0000;
  // thresholds per channel
  static constexpr uint16_t thresholds =         0x4000; // +2*ch
  // address registers
  static constexpr uint16_t address_source =     0x6000;
  static constexpr uint16_t address_reg =        0x6002;
  static constexpr uint16_t module_id =          0x6004;
  static constexpr uint16_t soft_reset =         0x6008;
  static constexpr uint16_t firmware_revision =  0x600e;
  // irq (roack)
  static constexpr uint16_t irq_level =          0x6010;
  static constexpr uint16_t irq_vector =         0x6012;
  static constexpr uint16_t irq_test =           0x6014;
  static constexpr uint16_t irq_reset =          0x6016;
  static constexpr uint16_t irq_data_thre =      0x6018;
  static constexpr uint16_t max_transfer_data =  0x601a;
  static constexpr uint16_t irq_source =         0x601c;
  static constexpr uint16_t irq_event_thre =     0x601e;
  // FIFO handling
  static constexpr uint16_t buffer_data_length = 0x6030;
  static constexpr uint16_t data_len_format =    0x6032;
  static constexpr uint16_t readout_reset =      0x6034;
  static constexpr uint16_t multi_event =        0x6036;
  static constexpr uint16_t marking_type =       0x6038;
  static constexpr uint16_t start_acq =          0x603a;
  static constexpr uint16_t FIFO_reset =         0x603c;
  static constexpr uint16_t data_ready =         0x603e;
  // operation mode
  static constexpr uint16_t bank_operation =     0x6040;
  static constexpr uint16_t resolution =         0x6042;
  static constexpr uint16_t output_format =      0x6044;
  static constexpr uint16_t adc_override =       0x6046;
  static constexpr uint16_t slc_off =            0x6048;
  static constexpr uint16_t skip_overrange =     0x604a;
  static constexpr uint16_t ignore_thresholds =  0x604c;
  // gate generator
  static constexpr uint16_t hold_delay0 =        0x6050; // adc
  static constexpr uint16_t hold_delay1 =        0x6052; // adc
  static constexpr uint16_t hold_width0 =        0x6054; // adc
  static constexpr uint16_t hold_width1 =        0x6056; // adc
  static constexpr uint16_t use_gg =             0x6058; // adc
  // trigger
  static constexpr uint16_t bank0_win_start =    0x6050; // tdc
  static constexpr uint16_t bank1_win_start =    0x6052; // tdc
  static constexpr uint16_t bank0_win_width =    0x6054; // tdc
  static constexpr uint16_t bank1_win_width =    0x6056; // tdc
  static constexpr uint16_t bank0_trig_source =  0x6058; // tdc
  static constexpr uint16_t bank1_trig_source =  0x605a; // tdc
  static constexpr uint16_t first_hit =          0x605c; // tdc
  // inputs, outputs
  static constexpr uint16_t input_range =        0x6060; // adc
  static constexpr uint16_t negative_edge =      0x6060; // tdc
  static constexpr uint16_t ECL_term =           0x6062;
  static constexpr uint16_t ECL_trig1_osc =      0x6064;
  static constexpr uint16_t ECL_out_config =     0x6066;
  static constexpr uint16_t trig_select =        0x6068;
  static constexpr uint16_t NIM_trig1_osc =      0x606a;
  static constexpr uint16_t NIM_busy =           0x606e;
  // pulser / threshold
  static constexpr uint16_t pulser_status =      0x6070;
  static constexpr uint16_t bank0_input_thre =   0x6078;
  static constexpr uint16_t bank1_input_thre =   0x607a;
  // control bus to external mesytec modules
  static constexpr uint16_t rc_busno =           0x6080;
  static constexpr uint16_t rc_modnum =          0x6082;
  static constexpr uint16_t rc_opcode =          0x6084;
  static constexpr uint16_t rc_adr =             0x6086;
  static constexpr uint16_t rc_dat =             0x6088;
  static constexpr uint16_t rc_ret_sta =         0x608a;
  // counter A
  static constexpr uint16_t reset_ctr_ab =       0x6090;
  static constexpr uint16_t evctr_lo =           0x6092;
  static constexpr uint16_t evctr_hi =           0x6094;
  static constexpr uint16_t ts_source =          0x6096;
  static constexpr uint16_t ts_divisor =         0x6098;
  static constexpr uint16_t ts_counter_lo =      0x609c;
  static constexpr uint16_t ts_counter_hi =      0x609e;
  // counter B
  static constexpr uint16_t adc_busy_time_lo =   0x60a0;
  static constexpr uint16_t adc_busy_time_hi =   0x60a2;
  static constexpr uint16_t time_0 =             0x60a8;
  static constexpr uint16_t time_1 =             0x60aa;
  static constexpr uint16_t time_2 =             0x60ac;
  static constexpr uint16_t stop_ctr =           0x60ae;
  // multiplicity filter
  static constexpr uint16_t high_limit0 =        0x60b0;
  static constexpr uint16_t low_limit0 =         0x60b2;
  static constexpr uint16_t high_limit1 =        0x60b4;
  static constexpr uint16_t low_limit1 =         0x60b6;
};

#endif
